<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>管理员注册</title>
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="/static/css/font.css">
	<link rel="stylesheet" href="/static/css/weadmin.css">
    <script src="/lib/layui/layui.js" charset="utf-8"></script>

</head>
<body class="login-bg">
    
    <div class="login">
        <div class="message">南方医院 v1.0-管理注册</div>
        <div id="darkbannerwrap"></div>
        
        <form  method="post" class="layui-form" >
            <input name="username" lay-verType="tips" placeholder="用户名"  type="text" lay-verify="required|username" class="layui-input" >
            <hr class="hr10">
            <input name="password" lay-verType="tips" lay-verify="required|pass" placeholder="密码"  type="password" class="layui-input">
            <hr class="hr10">
            <input lay-verType="tips" lay-verify="required|confirmPass" placeholder="确认密码"  type="password" class="layui-input">
            <hr class="hr10">
            <a href="/login" style="color:#189F92">用户登录？</a>
            <hr class="hr10">
            <input class="loginin" value="登录" lay-submit lay-filter="register" style="width:100%;" type="submit">
            <hr class="hr10" >
            <div>
            	
            </div>
        </form>
    </div>

    <script type="text/javascript">
        layui.extend({
            admin: '{/}/static/js/admin' // {/}的意思即代表采用自有路径，即不跟随 base 路径
        });
        layui.use(['form', 'admin','jquery'], function () {
            var form = layui.form,
                admin = layui.admin,
                $ = layui.jquery;

            //验证规则：
            form.verify({
                username: function (value, item) { //value：表单的值、item：表单的DOM对象
                        if (!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)) {
                            return '用户名不能有特殊字符';
                        }
                        if (/(^\_)|(\__)|(\_+$)/.test(value)) {
                            return '用户名首尾不能出现下划线\'_\'';
                        }
                        if (/^\d+\d+\d$/.test(value)) {
                            return '用户名不能全为数字';
                        }
                    }

                    ,
                pass: [
                    /^[\S]{6,12}$/, '密码必须6到12位，且不能出现空格'
                ],
                confirmPass:function(value,item){
                    if($('input[name=password]').val()!=value){
                        return "两次输入密码不一致"
                    }
                }
            });

            //监听提交
            form.on('submit(register)', function (data) {
                console.log(data.field); //{username: "wwww", password: "wvdd"}
               $.ajax({
                   url:'/login/register',
                   method:'post',
                   data:data.field
               }).then((res)=>{
                   if(res.msg=='ok'){
                    location.href='/login'
                   }else{
                        layer.open({
                            title: '提示信息'
                            ,content: res.msg
                        });     
    
                    }
                   
               })
               return false  //防止页面刷新
            });
        });
    </script>
    <!-- 底部结束 -->
</body>
</html>